<?php
	/**
	 * 获取雀神榜
	 */
    class Billboard extends APIBase {
		
		public $tag = "Billboard";
    	public $isLogin = false;
		
		public function before() {
			$this->initCacheRedis();
			return true;
		}
		public function logic() {
			//$ann = $this->cache_redis->hMGet("ha:*", array("id","title","content","image_url"));
			$userid = $this->param['playerID'];
			$billboard = $this->cache_redis->keys("hBillboard:*");			
			$count = count($billboard);
			$result = array();
			$data = array();
			if ($count) {
				for($i=0;$i<$count;$i++){	
				  $list = $this->cache_redis->hGetAll("hBillboard:".$i);
                  if($list['user_id']==$userid){
					$data = array('point'=>$list['win'],'rank'=>$list['num']); 
				  }	
                  if($i<=10){
					$result[] =  $list; 
				  }				   				 
				}
				
				$selfdata = array();
				if(empty($data)){
					$selfdata[]= array('point'=>'0','rank'=>'未入围');
				}elseif($data['rank']>10){
					$selfdata[]= array('point'=>$data['point'],'rank'=>'未入围');
				}elseif($data['rank']<=10){
					$selfdata[]= array('point'=>$data['point'],'rank'=>$data['rank']);
				}
				$this->returnData(array_merge($result,$selfdata));
			} else {
				$this->returnError(301,"对不起，暂无排行榜！");
			}

		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
